
var base64 = new Base64();
var draw = {
		vehicle_no_color: base64.decode(global.getUrlParam('vehicle_no_color')),
		lineObject: new Array(),
		starPic:appCtx+"resources/images/mapTool/start.png",
		endPic:appCtx+"resources/images/mapTool/end.png",
		pointMarker:null,
		pointInfoMarker:null,
		imageMarkerList:new Array(),
		markList:new Array(),
		reset:function(){
			draw.lineObject = new Array();
			draw.pointInfoMarker=null;
			draw.imageMarkerList=new Array();
			draw.markList=new Array();
		},
		setCenter:function(lon,lat){
			 mapTool.map.setCenter([lon,lat]);
		},
		closeInfoWindow:function() {
		    mapTool.map.clearInfoWindow();
		},
		cleanAll:function(map){
			if(null!=draw.pointMarker){
				map.remove(draw.pointMarker);
				//map.remove(draw.pointInfoMarker);
			}
			if(draw.pointInfoMarker){
				map.remove(draw.pointInfoMarker);
			}
			if(null!=draw.imageMarkerList){
				map.remove(draw.imageMarkerList);
			}
		},
		drawImage:function(imageList,map){
			draw.cleanAll(map);
			if(null!=imageList && imageList!=""){
				map.setZoom(13);				
				for(var i=0;i<imageList.length;i++){
					if(i==0){
						map.setCenter([imageList[i].gdLng,imageList[i].gdLat]);
					}
					var marker = new AMap.Marker({
				        map: map,
				        position: [imageList[i].gdLng,imageList[i].gdLat],
				        icon:appCtx+ "resources/images/mapTool/camera.png",
				    });
					var infoWindow = new AMap.InfoWindow({isCustom: true,offset: new AMap.Pixel(0, -10)}); 
					marker.content = "<div style='padding:15px;border:1px solid #dedede;background:#fff;position:relative;'>" +
							"<a  onclick='draw.closeInfoWindow()' style='position:absolute;top:3px;right:3px;background:url(" +
							"http://webapi.amap.com/images/close2.gif) 0 0 no-repeat;width:10px;height:10px;' href='javascript:;'></a>" +
							"<img class='db' style='height:200px;weight:300px;' src='"+imageList[i].imgUrl+"'>" +
									"<p style='padding-top:15px;'>拍照时间："+imageList[i].gpsTimeStr+"</p></div>";
					marker.on('click', function(e){
						 isopenWin=true;
						 infoWindow.setContent(e.target.content);
					     infoWindow.open(map, e.target.getPosition());			   	 
					});
					draw.imageMarkerList.push(marker);
					draw.imageMarkerList.push(infoWindow);
				}
			}
		},
		/**
		 * 画对应轨迹的地图标注
		 * 
		 * @param track
		 */
		drawPointMark:function(track){
			draw.cleanAll(mapTool.map);
			mapTool.map.setCenter(new AMap.LngLat(track.longitude, track.latitude));
			draw.pointMarker = new AMap.Marker({
    	        map:mapTool.map,
    	        position: [track.longitude, track.latitude],
    	        //icon: "http://webapi.amap.com/theme/v1.3/markers/n/mark_b.png"
    	        icon: appCtx + 'resources/images/mapTool/home_icon_location.png'
    	    });
			draw.pointInfoMarker = new AMap.InfoWindow({offset: new AMap.Pixel(0, -30)}); 
    		draw.pointMarker.content = '定位时间：'+track.gpsTimeS+'</br>速度：'+track.gpsSpeedF+' 公里/小时</br>里程：'+(track.gpsMileage).toFixed(1)+' 公里';
    		draw.pointMarker.on('click', function(e){
    			 isopenWin=true;
    			 draw.pointInfoMarker.setContent(e.target.content);
    			 draw.pointInfoMarker.open(mapTool.map, e.target.getPosition());    		   	 
    		});
    		draw.pointInfoMarker.open(mapTool.map, new AMap.LngLat(track.longitude, track.latitude));    
    		driverInfo(track.gpsTimeS);
		},
		/**
		 * 画点，有弹出窗
		 * 
		 * @param track
		 */
		/*showPoint:function(track){
			draw.drawPointMark(track);
		},*/
		/**
		 * 画轨迹线
		    {
		    map
			lineArr
			carPic
			trackColor
			passTrackColor
			lineSize
		    }
		 * @param options
		 */
		drawTrackLine:function(options){
			if(null!=draw.markList){
				options.map.remove(draw.markList);
				draw.lineObject.lineArr = null;
				draw.lineObject.marker= null;
			}
			isPlay = false;
			isGoCenter=false;
			draw.cleanAll(options.map);
			options.map.setZoom(13);
			// set map center
			mapTool.map.setCenter(options.lineArr[0]);
			// 车辆marker
			var marker = new AMap.Marker({
		        map: options.map,
		        position: options.lineArr[0],
		        icon: options.carPic,
		        offset: new AMap.Pixel(-20, -10)
		    });
			// 开始marker
			var startMarker = new AMap.Marker({
		        map: options.map,
		        position: options.lineArr[0],
		        icon: draw.starPic,
		        offset: new AMap.Pixel(-15, -30)
		    });
			// 结束marker
		    var endMarker = new AMap.Marker({
		        map: options.map,
		        position: options.lineArr[options.lineArr.length-1],
		        icon: draw.endPic,
		        offset: new AMap.Pixel(-15, -30)
		    });
		    // 绘制轨迹
		    var polyline = new AMap.Polyline({
		        map: options.map,
		        path: options.lineArr,
		        strokeColor: options.trackColor,  //线颜色
		        strokeWeight: options.lineSize,      //线宽
		    });
		    // 绘制已经播放过的线
		    var passedPolyline = new AMap.Polyline({
		        map: options.map,
		        strokeColor: options.passTrackColor,  //线颜色
		        strokeWeight: options.lineSize,      //线宽
		    });
		    marker.on('moving',function(e){
		        passedPolyline.setPath(e.passedPath);
		    })
		    
		    
		    options.map.setFitView();
		    
		    draw.lineObject.lineArr = options.lineArr;
		    draw.lineObject.marker=marker;
		    draw.markList.push(marker);
		    draw.markList.push(startMarker);
		    draw.markList.push(endMarker);
		    draw.markList.push(polyline);
		    draw.markList.push(passedPolyline);
		}
}

var tabUtils = {
		init:function(){
			this.tabInt = this.tab();
		},
		show:function(showIds,hidenIds,showTabIndex,updateTabName){
			tabUtils.tabInt.refash(showTabIndex);
			$("#tab_"+(showTabIndex)).html(updateTabName);
			for(var i=0;i<showIds.length;i++){
				$("#"+showIds[i]).show();
			}
			for(var i=0;i<hidenIds.length;i++){
				$("#"+hidenIds[i]).hide();
			}
		},
		/**
		 * tab页切换
		 */
		tab:function(){
			var index = 0;
			var func = function(){
				$('.trackTabTitle').find('.list').removeClass('active').eq(index).addClass('active');
				$('.trackTabCont').find('.list').hide().eq(index).show();
				$('.trackTab').find('.line').css({
					'left' : 100 * index + 'px'
				});
			};
			$('.trackTabTitle').find('.list').click(function(){
				index = $(this).index();
				func();
			});
			return {
				index : index,
				refash : function(i){			//外部点击时调用
					index = i;
					func();
				}
			};
		}
}
tabUtils.init();
/**
 * 轨迹查询业务
 */
var trackQuery = {
		
		allTrackList:null,
		alarmTrackList:null,
		currentTrackList:null,
		trackSplitPageIndex:0,//所有轨迹的分页
		alarmTrackSplitPageIndex:0,//报警轨迹的分页
		pageSize:500,
		
		reset:function(){
			trackQuery.allTrackList = null;
			trackQuery.alarmTrackList=null;
			trackQuery.currentTrackList=null;
			trackQuery.trackSplitPageIndex=0;
		},
		/**
		 * 查询报警路段的轨迹数据
		 * 
		 * @param obj
		 */
		showAlarmTrack:function(obj,type){
			
			if(0==type){
				$("#alarmDetailList2").hide();
				$("#trackList").show();
				$("#li_tab_2").show();
				$("#tab_2").html("报警段轨迹详情");
				trackSubSectin.tabInt.refash(2);
				trackQuery.queryTrack(obj.vehicleid,obj.startdatetime,obj.enddatetime,"trackTable");
			}else{
				$("#alarmTrackList").show();
				$("#li_tab_3").show();
				$("#tab_3").html("报警段轨迹详情");
				trackSubSectin.tabInt.refash(3);
				trackQuery.queryTrack(obj.vehicleid,obj.startdatetime,obj.enddatetime,"alarmTrackTable");
			}
		},		
		
		/**
		 * 查询报警路段的轨迹数据
		 * 
		 * @param obj
		 */
		showSubDetailTrack:function(vehicle_id,start_time,end_time,tbId){
			$("#alarmDetailList2").hide();
			$("#trackList").show();
			$("#li_tab_2").show();
			$("#tab_2").html("分段轨迹详情");
			trackSubSectin.tabInt.refash(2);
			trackQuery.queryTrack(vehicle_id,start_time,end_time,tbId);
		},	
		/**
		 * 画轨迹线
		 * 
		 * @param trackList
		 */
		showTrackSpeedLine:function(trackList,options){
			try{
				window.clearInterval(trackintsetInterval);
			}catch(e){
				
			}
			
			isPlay = false;
			isGoCenter=false;
			var lonlatArr = new Array();
			speedList = new Array();
			dateList = new Array();
			trackInfoArray = [];
			for(var i=0;i<trackList.length;i++){
				speedList[i]=trackList[i].gpsSpeedF;
				dateList[i]=trackList[i].gpsTimeS;
				trackInfoArray[i]=trackList[i];
				lonlatArr.push([trackList[i].longitude,trackList[i].latitude]);	
    		}	
			//charUtil.echart(speedList,dateList);
			draw.drawTrackLine({
			    	"map":mapTool.map,"lineArr":lonlatArr,"carPic":appCtx+"resources/images/mapTool/car1.png",
		    		"trackColor":options.color1,"passTrackColor":options.color2,"lineSize":options.lineSize
	    	});			
		},
		/**
		 * 查询所有轨迹，进入页面初始化的时候查询
		 * 
		 * @param vid 车牌号码
		 * @param star 开始时间
		 * @param end 结束时间
		 */
		/*queryAllTrack:function(vehicle_no_color,star,end){
			trackQuery.allTrackList = null;
			 $.ajax({
				 	url:appCtx+"gis/playback/queryList.html",
				 	data:{"vehicleId":vehicle_no_color,"starDate":star,"endDate":end,"merge_seconds":-1,"stop_seconds":-1},
					dataType : "JSON",
		            success : function(data){
		                if(data){
		                	trackQuery.allTrackList=data.rows;
		                	trackQuery.showTrackSpeedLine(trackQuery.allTrackList,{"color1":"#00A","color2":"#F00","lineSize":5});
		                }
		                global.ajaxLoading.close();
		            }
			 });
		},*/
		///==================内存轨迹数据及分页===============================///////
		/**
		 * 从内容load更多轨迹数据，按内存分页条数展示
		 */
		moreTrackList:function(tbId){
			var count = 0;
			for(var i=trackQuery.trackSplitPageIndex;i<trackQuery.currentTrackList.length;i++){
				trackQuery.trackSplitPageIndex=i;
				count++;
				$("#"+tbId).append(trackQuery.trackTrHtml(trackQuery.currentTrackList[i],i));
				if(count>=trackQuery.pageSize){
					trackQuery.trackSplitPageIndex=i+1;
					break;
				}
			}
			if(trackQuery.currentTrackList.length==(trackQuery.trackSplitPageIndex+1)){
				if(tbId=="trackTable"){
					$("#moreRows").hide();
				}else{
					$("#moreRows2").hide();
				}				
			}
		},
		/**
		 * 从内容load轨迹数据，按内存分页条数展示
		 */
		showAllTrackOneDay:function(){
			exportStartTime=$("#startTime").val();
			exportEndTime=$("#endTime").val();
			exportVehicleID=$("#selectVehicleSel").val();
			trackQuery.currentTrackList = trackQuery.allTrackList;//当前轨迹
			trackQuery.showTrackSpeedLine(trackQuery.allTrackList,{"color1":"#00A","color2":"#F00","lineSize":5});
			tabUtils.show(["trackList","li_tab_2"],["alarmDetailList2"],2,"轨迹详情");
			trackQuery.showFirstPageTrack("trackTable");
		},
		showFirstPageTrack:function(tbId){
			trackQuery.trackSplitPageIndex = 0;
			$("#"+tbId+" tr:not(:first)").remove();
			if(trackQuery.currentTrackList.length<=trackQuery.pageSize){
				if(tbId=="trackTable"){
					$("#moreRows").hide();
				}else{
					$("#moreRows2").hide();
				}				
			}else{
				if(tbId=="trackTable"){
					$("#moreRows").show();
				}else{
					$("#moreRows2").show();
				}				
			}
			for(var i=0;i<trackQuery.currentTrackList.length;i++){
				$("#"+tbId).append(trackQuery.trackTrHtml(trackQuery.currentTrackList[i],i));
				if(i>=(trackQuery.pageSize-1)){
					trackQuery.trackSplitPageIndex=i+1;
					break;
				}
			}
		},
		/**
		 * 轨迹拼装HTML 行
		 * @param track
		 * @param rowNumber
		 * @returns {String}
		 */
		/*trackTrHtml:function(track,rowNumber){
			var _class = "trackRow";
			if(rowNumber%2==0) _class = "meiyou"; else _class = "trackRow";
			return "<tr class="+_class+" onclick='draw.showPoint("+ JSON.stringify(track)+")'><td>"+(rowNumber+1)+"</td><td>"+track.gps_time+"</td><td>"+track.longitude+"</td><td>"+track.latitude+"</td><td>"+track.gps_speed+"</td><td>"+track.gps_mileage/10+"</td><td>"+track.status+"</td></tr>";
		},*/
		///==================内存轨迹数据及分页===============================///////
		
		/**
		 * 轨迹查询
		 * 
		 * @param vid
		 * @param star
		 * @param end
		 */
		queryTrack:function(vid,star,end,tbId){
			exportStartTime=star;
			exportEndTime=end;
			exportVehicleID=vid;
			 $.ajax({
				 	url:appCtx+"gis/playback/queryList.html",
				 	data:{"vehicleId":vid,"starDate":star,"endDate":end,"merge_seconds":-1,"stop_seconds":-1},
					dataType : "JSON",
		            success : function(data){
		            	alert("123")
		                if(data){
		                	trackQuery.alarmTrackList = data.rows;
		                	trackQuery.currentTrackList = trackQuery.alarmTrackList ;//当前轨迹
		                	trackQuery.showTrackSpeedLine(data.rows,{"color1":"#AE0000","color2":"#F00","lineSize":5});
		                	trackQuery.showFirstPageTrack(tbId);
		                }
		            }
			 });
		}
}

/**
 * 
 */
var trackSubSectin = {
		runList :new Array(),
    	stopList:new Array(),
    	allSubList:new Array(),
    	GlobalGpsCache:[],
    	
		reset:function(){
			trackSubSectin.runList = new Array();
			trackSubSectin.stopList=new Array();
			trackSubSectin.allSubList=new Array();
		},
		
    	clickQuery:function(){
    		var vehicle_no_color = $("#selectVehicleSel").val();
    		var starTime = $("#startTime").val();
    		var endTime = $("#endTime").val();
    		var end_str = (endTime).replace(/-/g,"/");//一般得到的时间的格式都是：yyyy-MM-dd hh24:mi:ss，所以我就用了这个做例子，是/的格式，就不用replace了。  
    		var end_date = new Date(end_str);//将字符串转化为时间  
    		//开始时间  
    		var sta_str = (starTime).replace(/-/g,"/");  
    		var sta_date = new Date(sta_str);  
    		var num = (end_date-sta_date)/(1000*3600*24);//求出两个时间的时间差，这个是天数  
    		var days = parseInt(Math.ceil(num));//转化为整天（小于零的话剧不用转了） 
    		if(days>3){
    			global.ajaxLoading.pop("查询时间不能超过三天",false,2000);
    			return;
    		}
    		if(days<0){
    			global.ajaxLoading.pop("开始时间必须小于结束时间",false,2000);
    			return;
    		}
    		if(vehicle_no_color != ""){
    			vehicle_no_color = base64.encode(vehicle_no_color);
    			trackSubSectin.querySubSection(vehicle_no_color,starTime,endTime);
    			trackSubSectin.initSubDetail();    		
    		}else{
    			global.ajaxLoading.pop("请选择车辆",false,2000);
    		}
    	},
    	queryByCondition:function(){
    		var vehicle_no_color = $("#selectVehicleSel").val();
    		/*var starTime = global.getUrlParam('starttime');
    		var endTime = global.getUrlParam('endtime');
    		if(starTime && endTime){
    			$("#startTime").val(starTime);
    			$("#endTime").val(endTime);
			}else{
				starTime = $("#startTime").val();
	    		endTime = $("#endTime").val();
			}*/
    		/*starTime = $("#startTime").val();
    		endTime = $("#endTime").val();*/
    		/*var time = global.getUrlParam('time');
    		if(time){
    			var starTime = time + ' 00:00:00';
    			var endTime = time + ' 23:59:59';
    			$("#startTime").val(starTime);
    			$("#endTime").val(endTime);
    		}else{
    			var starTime = $("#startTime").val();
	    		var endTime = $("#endTime").val();
    		}*/
    		var starTime = $("#startTime").val();
    		var endTime = $("#endTime").val();
    		if(vehicle_no_color!=""){
    			vehicle_no_color = base64.encode(vehicle_no_color);
    			trackSubSectin.querySubSection(vehicle_no_color,starTime,endTime);
    			trackSubSectin.initSubDetail();
    		}
    	},
    	echart : function(){
			var option = {
					tooltip : {
				        trigger: 'axis',
				        formatter: function (params) {
				            params = params[0];
				            return "时间:"+params.name+"<br/>"+"速度:"+params.value;
				        },
				        axisPointer: {
				        	animation: false
				        }
				    },
				    grid: {
				        left: '3%',
				        right: '3%',
				        top: '5%',
				        bottom:0,
				        containLabel: true
				    },
				    xAxis : [
				        {
				            type : 'category',
				            boundaryGap : false,
				            data :["-"]
				        }
				    ],
				    yAxis : [
				        {
				            type : 'value'
				        }
				    ],
				    series : [
				        {
				            name:'速度',
				            type:'line',
				            smooth:true,
				            data:[0]
				        }
				    ]
			};
			
			
			//$('#monitorCharts').html('');
			var myChart = echarts.init(document.getElementById('monitorCharts'));
	        myChart.setOption(option);
	        myChart.on("click", function(params){
	        	var name = params.name;
	        	var totalSubsectionLen = totalSubsection.length;
	        	for(var i=0;i<totalSubsectionLen;i++){
	        		if(totalSubsection[i].gpsTimeS == params.name){
	        			var da = totalSubsection[i];
	        			break;
	        		}
	        	}
	        	draw.drawPointMark(da);
	        });
	        return {
	        	option : option,
	        	chartDrivingDom : myChart
	        };
		},
		
    	loadVehicle:function(){
    		if(draw.vehicle_no_color){
    			var vehicle_no = draw.vehicle_no_color.split("_")[0];
    			var vehicle_color = global.carColor(draw.vehicle_no_color.split("_")[1]);
    			
				var selectStr="<option value='"+draw.vehicle_no_color+"'>" + vehicle_no + "(" + vehicle_color + ")" + "</option>";
				$('#selectVehicleSel').html(selectStr);
//				$("#selectVehicleSel").select2();
				return;
    		}
    		$("#selectVehicleSel").select2({
    	        theme: "default",
    	        allowClear: true,
    	        placeholder: "请选择车辆",
    	        ajax:{
    	            url:appCtx + "/gis/playback/loadUserVehicle.html",
    	            dataType:"json",
    	            delay:250,
    	            data:function(params){
    	                return {
    	                    name: params.term,
    	                    page: params.page || 1
    	                };
    	            },
    	            cache:true,
    	            processResults: function (res, params) {
				    	if(res){
				    		var options = [];
		    				$.each(res,function(index,obj) {
		    					var vehicle_no_color = obj.vehicle_no + "_" + obj.vehicle_color;
		    					var option = {"id":vehicle_no_color, "text":obj.vehicle_no + "(" + obj.vehicle_color_name + ")"};
	    	                    options.push(option);
		    				});
	    	                return {
	    	                	results: options,
	    	                    pagination: {
	    	                        more:false
	    	                    }
	    	                };
				    	}
    	            },
    	            escapeMarkup: function (markup) { return markup; },
    	            minimumInputLength: 1
    	        }
    	    });
    		
//    		var _this = this;
//			$.ajax({
//				   	type : 'post',
//				   	url : appCtx + "/gis/playback/loadUserVehicle.html",
//				   	dataType : "JSON",
//				   	success : function(data) {			
//				    	if(data){
//				    		var selectStr="";
//		    				selectStr+="<option value=''>请选择车辆</option>";
//		    				$.each(data,function(index,obj) {
//		    					var vehicle_no_color = obj.vehicle_no + "_" + obj.vehicle_color;
//		    					selectStr+="<option value='"+vehicle_no_color+"'>" + obj.vehicle_no + "(" + obj.vehicle_color_name + ")</option>";
//		    					
//		    				});
//		    				var vehicleId=$("#vehicleId").val();
//		    				$('#selectVehicleSel').html(selectStr);
//		    				if(draw.vehicle_no_color){
//		    					$("#selectVehicleSel").val(draw.vehicle_no_color);	
//		    				}		    				
//		    				$("#selectVehicleSel").select2();
    						//不自动查
//				    		trackSubSectin.queryByCondition();
//				    	}
//				   	}
//			   });
    	},
		init:function(){
			this.domH();
			this.chart = this.echart();
			this.loadVehicle();
			this.tabInt = this.tab();			
		},showSaveTrackLine:function(vehicle_id,start_time,end_time,start_lon,start_lat,end_lon,end_lat,mileage){
			curTrackLineM=mileage;
			if(start_lon=='0' || start_lat=='0'){
				startPositionTrackLine="";
			}else{
				var address = mapTool.initHashMap.GlobalAddressCache.get(start_lon+'_'+start_lat);
				if(address){
					startPositionTrackLine= address;
				}else{
					var geocoder = new AMap.Geocoder({
			            radius: 1000,
			            extensions: "all"
			        });        
			        geocoder.getAddress(new AMap.LngLat(start_lon, start_lat), function(status, result) {
			            if (status === 'complete' && result.info === 'OK') {
			            	var address=result.regeocode.formattedAddress;
			            	mapTool.initHashMap.GlobalAddressCache.put(start_lon+'_'+start_lat);
			            	startPositionTrackLine= address;
			            }
			        });     
				}	    
			}
			
			if(end_lon=='0' || end_lat=='0'){
				endPositionTrackLine="";
			}else{
				var address = mapTool.initHashMap.GlobalAddressCache.get(end_lon+'_'+end_lat);
				if(address){
					endPositionTrackLine= address;
				}else{
					var geocoder = new AMap.Geocoder({
			            radius: 1000,
			            extensions: "all"
			        });        
			        geocoder.getAddress(new AMap.LngLat(end_lon, end_lat), function(status, result) {
			            if (status === 'complete' && result.info === 'OK') {
			            	var address=result.regeocode.formattedAddress;
			            	mapTool.initHashMap.GlobalAddressCache.put(end_lon+'_'+end_lat);
			            	endPositionTrackLine= address;
			            }
			        });     
				}	    
			}
			
			vehicleIDTrackLIne=vehicle_id;
		    startTimeTrackLIne=start_time;
		    endTimeTrackLIne=end_time;
			$('#trackLinePop').modal('show');
		},
		
		//处理轨迹数据
		handTrack : function(jsonData){
			var _this = this;
	    	var GlobalGridField = ['vehicleNo','noColor','acc','chinaValid','gpsTimeS','gpsSpeedF','gpsMileage','longitude','latitude'];
	    	var tmpData = [],tmpValue = null;
	    	for(var i = 0; i < GlobalGridField.length; i++){
	    		tmpValue = jsonData[GlobalGridField[i]];

	    		if(tmpValue != undefined && tmpValue != null)
	    			tmpData.push(tmpValue);
	    		else
	    			tmpData.push("");
	    	}
	    	var gridData = {id:_this.GlobalGpsCache.length,data:tmpData};
	    	this.GlobalGpsCache.push(gridData); 
	    	//var gridData = {id:jsonData.vehicleId,data:tmpData};
	    	//index.GlobalGpsCache.put(jsonData.vehicleId,gridData);
	    },
		initSubDetail:function(){
			var _this = this;
			var initOptions = {	// 表格配置
			           tableId:'monitorList',
			           header:'车牌号,车牌颜色,ACC状态,精度,定位时间,速度,里程,经度,纬度',
			           colTypes:'ro,ro,ro,ro,ro,ro,ro,ro,ro',
			           code :'vehicleNo,noColor,acc,chinaValid,gpsTimeS,gpsSpeedF,gpsMileage,longitude,latitude',
			           initWidths:'100,100,100,70,150,80,120,160,160',
			           initWidthps:'100,100,100,70,150,80,120,160,160',
			           align:'left,left,left,left,left,left,left,left,left',
			           sort:'str,str,str,str,str,no,no,no,no'
			    	 };
			_this.myGrid = new dhtmlXGridObject(initOptions.tableId);
			_this.myGrid.setHeader(initOptions.header,null,["text-align:left;","text-align:left;","text-align:left;","text-align:left;","text-align:left;","text-align:left;","text-align:left;","text-align:left;","text-align:left;"]);//列标题
			_this.myGrid.setInitWidths(initOptions.initWidths);
			_this.myGrid.setColumnIds(initOptions.code);
			_this.myGrid.setColAlign(initOptions.align);//设置列数据的水平布局
			_this.myGrid.setColTypes(initOptions.colTypes);//设置列数据的数据类型(ch ---- checkbox; ra ---- radio;ro ---- readonly，双击具体某项数据时不可编辑的;txt ---- 显示的是字符串，双击某项数据会弹出编辑页面 )
			_this.myGrid.setColSorting(initOptions.sort);
			_this.myGrid.setSkin("dhx_skyblue");//指明使用什么皮肤
			_this.myGrid.enableAutoHeight(false,'auto',true);
			//index.myGrid.enableAutoHeight(false);
			_this.myGrid.init();
			_this.myGrid.enablePreRendering(1000);
			_this.myGrid.enableSmartRendering(true);
			_this.myGrid.attachEvent("onRowSelect",function(id,ind){
				draw.drawPointMark(totalSubsection[id]);
	    	 });
			/*$("#monitorList").flexigrid({
				dataType: 'json',
	            colModel : [{
	                display : '车牌号',
	                name : 'vehicleNo',
	                width : 100,
	                sortable : false,
	                align : 'left',
	                className:'cursor',
	                paramcolnames : ['vehicle_id','start_time','end_time'],
	                handlefunction:queryTrackDetailInfo
	             },{
	            	 display: '车牌颜色',
	            	 name: 'noColor',
	            	 width: 100,
	            	 sortable: false,
	            	 align: 'left'
	            	 
	             },{
	            	 display: 'ACC状态',
	            	 name: 'acc',
	            	 width: 100,
	            	 sortable: false,
	            	 align: 'left'
	             },{
	            	 display: '精度',
	            	 name: 'chinaValid',
	            	 width: 100,
	            	 sortable: false,
	            	 align: 'left'
	             },{
	            	 display: '定位时间',
	            	 name: 'gpsTimeS',
	            	 width: 150,
	            	 sortable: false,
	            	 align: 'left'
	             },{
	            	 display: '速度',
	            	 name: 'gpsSpeedF',
	            	 width: 120,
	            	 sortable: false,
	            	 align: 'left'
	             },{
	            	 display: '里程',
	            	 name: 'gpsMileage',
	            	 width: 120,
	            	 sortable: false,
	            	 align: 'left'
	             },{
	            	 display: '经度',
	            	 name: 'longitude',
	            	 width: 150,
	            	 sortable: false,
	            	 align: 'left'
	             },{
	            	 display: '纬度',
	            	 name: 'latitude',
	            	 width: 150,
	            	 sortable: false,
	            	 align: 'left'
	             }],
	             resizable : false,
		         sortname : "start_time",// 第一次加载数据时排序列
		         sortorder : "desc",// 第一次加载数据时排序类型
		         usepager : false,// 是否分页，默认为true。
		         showToggleBtn : false,
		         showTableToggleBtn : false,// 是否显示收起/打开按钮,默认不显示。
		         useRp : true,// 是否可以动态设置每页显示的结果数，默认为false。
		         rp : 10,// 每页记录数，默认为10
		         rpOptions: [10,50,100,300,500], // 每页结果数
		         checkbox : false,// 是否要多选框,默认为false。
		         singleSelect : true,
		         width : 'auto',// 表格宽度
		         height : _this.flexHeight, // 表格高度
		         titDisplay:false,
		         onSuccess : function(data){
		        	 trackQuery.allTrackList=data.rows;
		        	 trackQuery.showTrackSpeedLine(trackQuery.allTrackList,{"color1":"#00A","color2":"#F00","lineSize":5});
		        	 global.ajaxLoading.close();
		         },
		         onSelectRow : function(row,title){
		        	 draw.drawPointMark(row);
		         }
			})*/
		},
		/**
		 * tab页切换
		 */
		tab : function(){
			var index = 0;
			var func = function(){
				$('.trackTabTitle').find('.list').removeClass('active').eq(index).addClass('active');
				$('.trackTabCont').find('.list').hide().eq(index).show();
				$('.trackTab').find('.line').css({
					'left' : 100 * index + 'px'
				});
			};
			$('.trackTabTitle').find('.list').click(function(){
				index = $(this).index();
				func();
			});
			return {
				index : index,
				refash : function(i){			//外部点击时调用
					index = i;
					func();
				}
			};
		},		
		closeQueryCondition:function(){
			$("#queryCondition").hide();
			$("#showQueryPanel").show();
		},
		openQueryCondition:function(){
			$("#queryCondition").show();
			$("#showQueryPanel").hide();
		},
		/**
		 * 各dom高度
		 * */
		domH : function(){
			var winH = $(window).height();
			$('#mymap').height(winH-330);
			this.flexHeight = 157;
		},
		
		queryDriverInfo: function(params){
			$.ajax({
				url: appCtx+'gis/playback/queryDriverList.html',
				dataType: 'json',
				type: 'get',
				data: params,
				success: function(data){
					for(var i=0;i<data.length;i++){
						data[i].startTimes = new Date(data[i].startTime).getTime();
						data[i].endTimes = new Date(data[i].endTime).getTime();
					}
					queryDriverInfoData = data;
				}
			});
		},
		querySubSection:function(vehicle_no_color,star,end){	
			var _this = this;
			$("#objTable tr:eq(1)").remove(); 
			$("#alarmTrackTable tr:not(:first)").remove();
			$("#trackTable tr:not(:first)").remove(); 
			$("#alarmDetailTable tr:not(:first)").remove();
			$("#alarmDetailTable2 tr:not(:first)").remove();
			//$("#monitorList").flexAddData({"rows":""});
			if(_this.myGrid){
				_this.myGrid.clearAll();
			}
			$("#playControlBox").hide();
			//charUtil.echart([],[]);
			mapTool.map.clearMap();
			draw.reset();
			trackQuery.reset();
			trackSubSectin.reset();
			//tabUtils.show([],["trackList","monitorList","alarmDetailList","alarmDetailList2","alarmTrackList","li_tab_2","li_tab_3"],0,"轨迹汇总信息");
			var getTimestamp=new Date().getTime();
			trackSubSectin.queryDriverInfo({"vehicle_no_color":vehicle_no_color,"start_time":star,"end_time":end});
			global.ajaxLoading.pop('正在拼命加载,请稍候!',true);
			 $.ajax({
		            url : appCtx+'gis/playback/queryTrackList.html',
		            data:{"vehicle_no_color":vehicle_no_color,"start_time":star,"end_time":end,v:getTimestamp},
		            dataType : "JSON",
		            success : function(data){
		            	_this.GlobalGpsCache = [];
		                if(data && data.rows.length > 0){
		                	//draw.cleanAll(mapTool.map);
		                	//_this.queryDriverInfo(data.rows[0].driver);
		                	var rowLen = data.rows.length; 
		                	var timeArr = [];
		                	var speedArr = [];
		                	for(var i=0;i<rowLen;i++){
		                		var row = data.rows[i];
		                		timeArr.push(row.gpsTimeS);
		                		speedArr.push(row.gpsSpeedF);
		                		row.noColor = global.carColor(row.vehicleColor);
		                		row.acc = row.accStatus ? '开' : '关';
		                		//row.head = mapTool.getChinaHead(row.head);
		                		row.chinaValid = row.validS;
		                		_this.handTrack(row);
		                	}
		                	_this.chart.option.xAxis[0].data = timeArr;
		                	_this.chart.option.series[0].data = speedArr;
		                	_this.chart.chartDrivingDom.setOption(_this.chart.option);
		                	totalSubsection = data.rows;
		                	//$("#monitorList").flexAddData({"rows":data.rows});
		                	GlobalGpsCacheData = {
		                			rows: _this.GlobalGpsCache
		                	};
		                	_this.myGrid.parse(GlobalGpsCacheData,"json");
		                	trackQuery.allTrackList=data.rows;
				        	trackQuery.showTrackSpeedLine(trackQuery.allTrackList,{"color1":"#00A","color2":"#F00","lineSize":5});
		                	$("#playControlBox").show();
	                		trackSubSectin.closeQueryCondition();
	                		global.ajaxLoading.close();
		                }else{
		                	//$("#objTable tr:eq(0)").after("<tr><td colspan='10'>无数据</td></tr>"); 
		                	_this.chart.option.xAxis[0].data = [star];
		                	_this.chart.option.series[0].data = [0];
		                	_this.chart.chartDrivingDom.setOption(_this.chart.option);
		                	global.ajaxLoading.pop("查询无结果",false,1500);
		                }
		            }
		        });
		}
}